//
//  NSArray+URLAddtion.m
//  Gunterapple
//
//  Created by 热带雨林 on 2020/3/31.
//  Copyright © 2020 热带雨林. All rights reserved.
//

#import "NSArray+URLAddtion.h"

//#import <AppKit/AppKit.h>
@implementation NSArray (URLAddtion)

+ (instancetype)gg_arrayModelWithPlistName:(NSString *)plistName withClassName:(NSString *)className {
    
    //存在局限性，不能使用model嵌套model的类型
    NSURL *url = [[NSBundle mainBundle]URLForResource:plistName withExtension:nil];
    NSArray *array = [NSArray arrayWithContentsOfURL:url];
    NSMutableArray *muarray = [NSMutableArray array];
    Class cla = NSClassFromString(className);
    for (NSDictionary *dic in array) {
        //根据名称实例化对象
        NSObject *obj = [[cla alloc]init];
        [obj setValuesForKeysWithDictionary:dic];
        [muarray addObject:obj];
    }
    //可以返回任何所需要的值
    return muarray;
}

//
+ (instancetype)gg_arrayDataWithPlistName:(NSString *)plistName{
    NSURL *url = [[NSBundle mainBundle]URLForResource:plistName withExtension:nil];
    return [NSArray arrayWithContentsOfURL:url];
}

@end
